package com.gitee.wsl.struct.table.mini.dsl

import com.gitee.wsl.struct.table.mini.BorderStyle
import com.gitee.wsl.struct.table.mini.Table
import com.gitee.wsl.struct.table.mini.TableStyle

@PicnicDsl
interface TableDsl : TableSectionDsl {
    fun header(content: TableSectionDsl.() -> Unit)
    fun body(content: TableSectionDsl.() -> Unit)
    fun footer(content: TableSectionDsl.() -> Unit)
    fun style(content: TableStyleDsl.() -> Unit)
}

internal class TableDslImpl : TableDsl {
    private val headerImpl = TableSectionDslImpl()
    private val bodyImpl = TableSectionDslImpl()
    private val footerImpl = TableSectionDslImpl()
    private val cellStyleImpl = CellStyleDslImpl()
    private val tableStyleImpl = TableStyleDslImpl()

    override fun header(content: TableSectionDsl.() -> Unit) {
        headerImpl.apply(content)
    }

    override fun body(content: TableSectionDsl.() -> Unit) {
        bodyImpl.apply(content)
    }

    override fun footer(content: TableSectionDsl.() -> Unit) {
        footerImpl.apply(content)
    }

    override fun row(content: RowDsl.() -> Unit) {
        bodyImpl.row(content)
    }

    override fun cellStyle(content: CellStyleDsl.() -> Unit) {
        cellStyleImpl.apply(content)
    }

    override fun style(content: TableStyleDsl.() -> Unit) {
        tableStyleImpl.apply(content)
    }

    fun create() = Table {
        header = headerImpl.createOrNull()
        body = bodyImpl.create()
        footer = footerImpl.createOrNull()
        cellStyle = cellStyleImpl.createOrNull()
        tableStyle = tableStyleImpl.createOrNull()
    }
}
